﻿// src/crudOption/service/serviceList.js
export default formData => {
  // ===== 搜索 =====
  const searchOption = ref({
    formConfig: {
      tenantName: { label: "客户名称", component: "el-input" },
      tenantId: { label: "客户ID", component: "el-input" },
      status: {
        label: "开通状态",
        component: "el-select",
        defaultValue: "",
        dicData: [
          { label: "全部", value: "" },
          { label: "已开通", value: 1 },
          { label: "已关闭", value: 2 },
        ],
        dicProps: { label: "label", value: "value" },
        placeholder: "全部",
        clearable: true,
      },
    },
  });

  // ===== 表格/表单 =====
  const tableOption = ref(
    Utils.tools.deleteSearchConfig({
      addTitle: "",
      editTitle: "",
      dialogWidth: "30%", // 20% 在窄屏可能太小，这里给个像素更稳；按需改回

      // 是否显示编辑按钮
      editBtn: false,
      // 是否显示删除按钮
      delBtn: false,

      menuWidth: 80,
      // 对齐方式
      align: "left",
      // 表格配置
      /**
       * 弹窗表单（与原型一致）
       */
      group: [
        {
          column: {
            // 1) 资费
            fee: {
              label: "资费",
              span: 24,
              placeholder: "请输入资费",
              type: "input",
              value: "0.1",
              clearable: true,
              rules: [
                { required: true, message: "请输入正确资费", trigger: "blur" },
                {
                  validator: (_r, v, cb) => (v > 0 ? cb() : cb(new Error("请输入正数"))),
                  trigger: "blur",
                },
              ],
            },

            // 2) 成本
            cost: {
              label: "成本",
              span: 24,
              placeholder: "请输入成本",
              type: "input",
              value: "0.1",
              clearable: true,
              rules: [
                { required: true, message: "请输入正确成本", trigger: "blur" },
                {
                  validator: (rule, value, callback) => {
                    if (Number(value) <= 0) {
                      callback(new Error("请输入正数"));
                    } else if (Number(value) > Number(formData.value.fee)) {
                      callback(new Error("成本不能大于资费"));
                    } else {
                      callback();
                    }
                  },
                  trigger: "blur",
                },
              ],
            },
          },
        },
      ],

      /**
       * 列表列
       */
      column: {
        // 客户名称
        tenantName: { label: "客户名称", minWidth: 180, display: false },
        // 客户ID
        tenantId: { label: "客户ID", minWidth: 150, display: false },
        // 资费
        tenantFee: {
          label: "资费",
          minWidth: 150,
          display: false,
        },
        // 成本
        tenantCost: {
          label: "成本",
          minWidth: 150,
          display: false,
        },
        // 使用次数
        useCount: {
          label: "使用次数",
          minWidth: 150,
          display: false,
        },
        // 使用费用
        useFee: {
          label: "使用费用",
          minWidth: 100,
          display: false,
        },
        // 利润
        useProfit: {
          label: "利润",
          minWidth: 100,
          display: false,
        },
        status: {
          label: "开通状态",
          width: 120,
          dicData: [
            { label: "关闭", value: 2 },
            { label: "开通", value: 1 },
          ],
          display: false, // 列表里你用自定义 slot + 开关，所以这里不渲染内置
        },
      },
    })
  );

  return { searchOption, tableOption };
};
